#include <iostream>
#include <vector>
using namespace std;

class Solution {
	int count = 0;
	bool dfs(vector<string> &digits, int cur, int idx,int target)
	{
		if (cur <= target) {
                        //cout << cur << " ";
			count++;
		}
                for(int i = 0; i < digits.size(); i++){
			if (cur + (digits[i][0] - '0') * 10 + (digits[i][1] - '0') <= target) {
				dfs(digits, cur + (digits[i][0] - '0') * 10 + (digits[i][1] - '0'), i + 1, target);
			}
			return true;
		}
                return true;
	}

    public:
	int atMostNGivenDigitSet(vector<string> &digits, int n)
	{
                dfs(digits, 0, 0, n);
                return count;
	}
};

int main()
{
	vector<string> digits = { "1","4","9"};
	int n = 1000000000;
	cout << Solution().atMostNGivenDigitSet(digits, n) << endl;
	return 0;
}